import { defineStore } from 'pinia';
import { ref } from 'vue'

export const useMemberStore = defineStore('member', () => {
	
	// 保存登录会员信息
	let profile = ref({})
	let setProfile = (val) => {
		profile.value = val
		saveUserToStorage()
	}
	
	// 把会员信息存到本地
	let saveUserToStorage = () => {
		uni.setStorageSync('member', profile.value)
	}
	
	// 退出登录
	let clearProfile = () => {
		// 这里设置成undefined 其他页面可以这样判断v-if="memberStore.profile"
		// {} 还是true
		profile.value = undefined
		uni.clearStorageSync('member')
	}
	
	
	// 预付订单页面选择收货地址
	let selecteAddress = ref()
	let changeSelecteAddress = (val) => {
		selecteAddress.value = val
	}
	
	

	return {
		profile,
		setProfile,
		clearProfile,
		selecteAddress,
		changeSelecteAddress
	};
});